<%@page import="java.util.Map"%>
<%@page import="java.util.HashMap"%>
<%@page import="entity.Student"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<!-- 1、 向域对象中放数据-->
	<%
		request.setAttribute("age", 23);
		request.setAttribute("gender", "男");
	%>
	<!-- scope: page、request、session、application
	如果没有给定scope，默认情况是page。 -->
	<c:set var="age" value="20" scope="request"></c:set>
	${age}
	<hr/>
	
	<!-- 2、但条件判断 -->
	<c:if test="${age==20}">
		今年20岁了
	</c:if>
	
	<c:if test="${gender=='男'}">
		男
	</c:if>
	<c:if test="${gender=='女'}">
		女
	</c:if>
	<hr/>
	
	<!-- 3、多条件判断 -->
	<c:set var="score" value="40"></c:set>
	<c:choose>
		<c:when test="${score>=90 && score<=100}">
			优秀
		</c:when>
		<c:when test="${score>=80 && score<90}">
			良好
		</c:when>
		<c:when test="${score>=70 && score<80}">
			一般
		</c:when>
		<c:when test="${score>=60 && score<70}">
			及格
		</c:when>
		<c:otherwise>
			不及格
		</c:otherwise>
	</c:choose>
	<hr/>
	
	<!-- 4、集合遍历 
		4.1、 List<String>
		4.2、 List<Student>
		4.3、 Map<String,String>
			 Map<String, Student>
	-->
	<!-- 遍历1-10 
		step="2" 类似于for循环中把i++改为i+=2
	-->
	<c:forEach begin="1" end="10" var="i" step="2">
		${i}
	</c:forEach>
	<br/>
	<!-- 4.1、 List<String> -->
	<%
		List<String> list = new ArrayList<String>();
		list.add("中国");
		list.add("美国");
		list.add("英国");
		request.setAttribute("list", list);
	%>
	<c:forEach items="${list}" var="str">
		${str}
	</c:forEach>
	<hr/>
	
	<!-- 4.2、 List<Student> -->
	<%
		List<Student> stuList = new ArrayList<Student>();
		Student student1 = new Student(1, "张三1", 23, "男");
		Student student2 = new Student(2, "张三2", 23, "男");
		Student student3 = new Student(3, "张三3", 23, "男");
		stuList.add(student1);
		stuList.add(student2);
		stuList.add(student3);
		request.setAttribute("stuList", stuList);
	%>
	<c:forEach items="${stuList}" var="student">
		${student}--- ${student.name}<br/>
	</c:forEach>
	<hr/>
	
	<!-- 4.3、 Map<String,String> -->
	<%
		Map<String, String> map = new HashMap<String, String>();
		map.put("cn", "中国");
		map.put("us", "美国");
		request.setAttribute("map", map);
	%>
	<c:forEach items="${map}" var="entry">
		${entry.key}--${entry.value} <br/>
	</c:forEach>
	<!-- Map<String, Student> -->
	<%
		Map<String, Student> stuMap = new HashMap<String, Student>();
	    stuMap.put("stu1", student1);
	    stuMap.put("stu2", student2);
	    stuMap.put("stu3", student3);
	    request.setAttribute("stuMap", stuMap);
	%>
	<c:forEach items="${stuMap}" var="entry">
		${entry.key}--${entry.value}--${entry.value.name}<br/>
	</c:forEach>
	
</body>
</html>